package com.example.hello.client.Icon;

import com.example.hello.BootstrapIcon;
import com.github.gwtbootstrap.client.ui.constants.Alignment;
import com.github.gwtbootstrap.client.ui.constants.IconSize;
import com.github.gwtbootstrap.client.ui.constants.IconType;
import com.google.gwt.core.client.GWT;
import com.google.gwt.user.client.ui.Widget;
import com.vaadin.client.communication.StateChangeEvent;
import com.vaadin.client.ui.AbstractComponentConnector;
import com.vaadin.shared.ui.Connect;

@Connect(BootstrapIcon.class)
public class BootstrapIconConnector extends AbstractComponentConnector {

    @Override
    protected Widget createWidget() {
        return GWT.create(VBootstrapIcon.class);
    }

    @Override
    public VBootstrapIcon getWidget() {
        return (VBootstrapIcon) super.getWidget();
    }

    @Override
    public BootstrapIconState getState() {
        return (BootstrapIconState) super.getState();
    }

    @Override
    public void onStateChanged(StateChangeEvent stateChangeEvent) {
        super.onStateChanged(stateChangeEvent);

        BootstrapIconState state = getState();

        VBootstrapIcon icon = getWidget();

        icon.setAlignment(Alignment.valueOf(state.getAlignment()));
        icon.setSpin(state.isSpin());
        icon.setLight(state.isLight());
        icon.setMuted(state.isMuted());
        icon.setIcon(IconType.valueOf(state.getType()));
        icon.setSize(IconSize.valueOf(state.getIconSize()));
    }

}
